﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

/// <summary>
/// Summary description for bzNewsCate
/// </summary>
public class bzVideo
{
	private dbConnection _DB = null;
    private string _TableName = "bzVideo";
    private string _IDType = "_INT";
    private string _IDCol = "VideoID";
    private string _TableChild = "bzNewsOne";
    private string _IDColParent = "";

    private static string _Cate = "1";
    public static string Cate { get { return _Cate; } }

    private static string _NotCate = "0";
    public static string NotCate { get { return _NotCate; } }

    public bzVideo()
	{
        _DB = new dbConnection();
	}
    public DataTable getTable(string Key,string Enabled,string Page,string Limit)
    {       
        SqlParameter[] p = new SqlParameter[4];
        p[0] = new SqlParameter("@Key", "%" + Key + "%");
        p[1] = new SqlParameter("@Enabled",  Enabled );       
        p[2] = new SqlParameter("@Page", Page);
        p[3] = new SqlParameter("@Limit", Limit);
        return _DB.getDataTable(_TableName+"_search",p);
       
    }
    public long getTotal(string Key, string Enabled)
    {
        SqlParameter[] p = new SqlParameter[2];        
        p[0] = new SqlParameter("@Key", "%" + Key + "%");
        p[1] = new SqlParameter("@Enabled", Enabled);
        return _DB.getTotalTable(_TableName+"_getTotal",p);
    }
    public DataTable getRecord(string ID)
    {
        return this.getRecord(ID, "-1");
    }
    public DataTable getRecord(string ID, string Enabled)
    {
        SqlParameter[] p = new SqlParameter[4];
        p[0] = new SqlParameter("@TableName", _TableName);
        p[1] = new SqlParameter("@IDCol", _IDCol);
        p[2] = new SqlParameter("@IDValue", ID);
        p[3] = new SqlParameter("@Enabled", Enabled);
        return _DB.getDataTable("bz_getRecord" + _IDType, p);
    } 
    public int deleteRecord(string[] ID)
    {
        int count = 0;
        foreach (string str in ID)
        {
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@TableName", _TableName);
            p[1] = new SqlParameter("@TableChild", _TableChild);
            p[2] = new SqlParameter("@IDCol", _IDCol);
            p[3] = new SqlParameter("@IDValue", str);
            count += _DB.updateData("bz_deleteRecord" + _IDType, p);
        }
        return count;
    }
    public int activeRecord(string[] ID, string Enabled)
    {
        int count = 0;
        foreach (string str in ID)
        {
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@TableName", _TableName);
            p[1] = new SqlParameter("@IDCol", _IDCol);
            p[2] = new SqlParameter("@IDValue", str);
            p[3] = new SqlParameter("@Enabled", Enabled);
            count += _DB.updateData("bz_activeRecord" + _IDType, p);
        }
        return count;
    }

    public int saveOrder(string[] ID, string[] Order)
    {
        if (ID.Length != Order.Length) return 0;
        int count = 0;
        for (int i = 0; i < ID.Length; i++)
        {
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@TableName", _TableName);
            p[1] = new SqlParameter("@IDCol", _IDCol);
            p[2] = new SqlParameter("@IDValue", ID[i]);
            p[3] = new SqlParameter("@Order", Order[i]);
            count += _DB.updateData("bz_saveOrder" + _IDType, p);
        }
        return count;

    }
    public int upOrder(string ID)
    {
        SqlParameter[] p = new SqlParameter[3];
        p[0] = new SqlParameter("@TableName", _TableName);
        p[1] = new SqlParameter("@IDCol", _IDCol);
        p[2] = new SqlParameter("@IDValue", ID);
        return _DB.updateData("bz_upOrder" + _IDType, p);
    }
    public int downOrder(string ID)
    {
        SqlParameter[] p = new SqlParameter[3];
        p[0] = new SqlParameter("@TableName", _TableName);
        p[1] = new SqlParameter("@IDCol", _IDCol);
        p[2] = new SqlParameter("@IDValue", ID);
        return _DB.updateData("bz_downOrder" + _IDType, p);
    }   
    public int insertRecord(string NameVN, string Url, string Enabled)
    {
        SqlParameter[] p = new SqlParameter[3];
        p[0] = new SqlParameter("@NameVN", NameVN);
        p[1] = new SqlParameter("@Url", Url);
      
        p[2] = new SqlParameter("@Enabled", Enabled);
       
        return _DB.updateData(_TableName+"_insert",p);
    }
    public int updateRecord(string ID, string NameVN, string Url,  string Enabled)
    {
        SqlParameter[] p = new SqlParameter[4];
        p[0] = new SqlParameter("@ID", ID);
        p[1] = new SqlParameter("@NameVN", NameVN);
        p[2] = new SqlParameter("@Url", Url);
       
        p[3] = new SqlParameter("@Enabled", Enabled);
      
        return _DB.updateData(_TableName + "_update", p);
    }  
}
